home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Unable to check calloc's return values
- Date: 31 Jan 1996 13:12:05 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4eobdl$5bj@umbc9.umbc.edu>
- References: <4emept$ifv@hpg30a.csc.cuhk.hk>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- CHAN CHUN CHUNG <s910500@acs.csc.cuhk.hk> wrote:
- |> Could anyone tell me why the following line is complained by the
- |> compiler?
- |>
- |> if ((float **x = (float **) calloc(9, sizeof(float *)))
- |> == 0) exit(1);
- |>
- |> What's the right way to check the calloc's return value?
-
- The correct way is:
-
- #include <stdlib.h>
- ...
- float **x;
- ...
- if ((x = calloc (9, sizeof (*x))) == NULL)
- exit (1);
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-